package home.contaduria.dao.jpa;

import home.contaduria.dao.ExpenseDao;
import home.contaduria.domain.Client;
import home.contaduria.domain.Expense;

import java.util.List;

import org.springframework.stereotype.Repository;

@Repository("expenseDaoJpaImpl")
public class ExpenseDaoJpaImpl extends GenericDaoJpaImpl<Expense, Long> implements ExpenseDao {

    @Override
    public List<Expense> findExpenses(Client client) {
        return getEntityManager().createNamedQuery("Expense.findClientExpenses", Expense.class).setParameter("client", client)
                .getResultList();
    }

    @Override
    public List<Expense> findExpenses(Client client, int firstResult, int maxResults) {
        return getEntityManager().createNamedQuery("Expense.findClientExpenses", Expense.class).setParameter("client", client)
                .setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

    @Override
    public Long countExpensesNumber(Client client) {
        return getEntityManager().createNamedQuery("Expense.countClientExpenses", Long.class).setParameter("client", client)
                .getSingleResult();
    }

}
